<?php
namespace app\admin\model;

use think\Model;

class ComUserModel extends Model
{
    // 确定链接表名
    protected $table = 'wb_buser';

    /**
     * 根据搜索条件获取用户列表信息
     * @param $where
     * @param $offset
     * @param $limit
     */
    public function getUsersByWhere($where, $offset, $limit)
    {
        return $this->table('wb_buserinfo')->alias('i')
                    ->join('wb_buser b','b.id=i.uid')
                    ->field('*')
                    ->where('role = 1')
                    ->where($where)->limit($offset, $limit)->order('b.id desc')->select();
    }

    /**
     * 根据搜索条件获取所有的用户数量
     * @param $where
     */
    public function getAllUsers($where)
    {
        return $this->table('wb_buser')->alias('b')
        ->join('wb_buserinfo i','b.id=i.uid')
        ->field('*')
        ->where($where)
        ->where('b.role','=','1')
        ->count();
    }

    /**
     * 改变活动状态
     * @param $id $s
     */
    public function editStatus($id ,$s)
    {
        $t = $s==1?2:1;
        $data = ['status'=>$t];
        try{

            $this->where('id', $id )->update($data);
            return msg(1, '', '修改成功');

        }catch(\Exception $e){
            return msg(-1, '', $e->getMessage());
        }
    }


}